import axios from 'axios'
import { AXIOS_DEFAULT_CONFIG } from '@/config'
import {
  requestSuccessFunc,
  requestFailFunc,
  responseSuccessFunc,
  responseFailFunc
} from '@/plugins/axios/config'
  
let axiosInstance = {}
axiosInstance = axios.create(AXIOS_DEFAULT_CONFIG)

// 注入请求拦截
axiosInstance
    .interceptors.request.use(requestSuccessFunc, requestFailFunc)

// 注入失败拦截
axiosInstance
    .interceptors.response.use(responseSuccessFunc, responseFailFunc)

export default function $axios(url, type, data) {
    const options = {
        url,
        method: type,
    }
    if (type === 'POST') {
        options.data = data
    } else if (type === 'GET') {
        options.params = data
    }
    return axiosInstance(options)
}

